home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Risc World 3
/
Risc World 3.iso
/
SOFTWARE
/
ISSUE6
/
PD
/
PDF
/
GuiLib
/
Task
/
c++
/
GuiObject
< prev
next >
Wrap
Text File
|
2003-02-14
|
7KB
|
225 lines
//--------------------------------------------------------------------------
//
// Copyright (c) 2002, Colin Granville
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or
// without modification, are permitted provided that the following
// conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// * The name Colin Granville may not be used to endorse or promote
// products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
//
//--------------------------------------------------------------------------
#include "GuiObject.h"
#include "GuiWindow.h"
#include "swis.h"
#include "gfx.h"
#include "ERROR.h"
int GuiObject::getValue(int method_code,int fail_value) const
{
int result=fail_value;
_swix(Toolbox_ObjectMiscOp,_INR(0,2) | _OUT(0),0,id(),method_code,&result);
return result;
}
//********************************************************************************
bool GuiObject::getValue(int method_code,void* value) const
{
if (value==NULL) return 0;
return _swix(Toolbox_ObjectMiscOp,_INR(0,3),0,id(),method_code,value)==NULL;
}
//********************************************************************************
void GuiObject::setValue(int method_code,int value)
{
_swix(Toolbox_ObjectMiscOp,_INR(0,3),0,id(),method_code,value);
}
//********************************************************************************
void GuiObject::setValue(int method_code,const void* value)
{
_swix(Toolbox_ObjectMiscOp,_INR(0,3),0,id(),method_code,value);
}
//********************************************************************************
string GuiObject::getString(int method_code) const
{
string s;
_kernel_swi_regs reg;
reg.r[0]=0;
reg.r[1]=id();
reg.r[2]=method_code;
reg.r[3]=0;
reg.r[4]=0;
if (_kernel_swi(Toolbox_ObjectMiscOp,®,®)==NULL)
{
s.resize(reg.r[4]-1);
if (s.size()==reg.r[4]-1)
{
reg.r[3]=(int)s.data();
_kernel_swi(Toolbox_ObjectMiscOp,®,®);
}
}
return s;
}
//********************************************************************************
void GuiObject::setString(int method_code,const char* str)
{
_swix(Toolbox_ObjectMiscOp,_INR(0,3),0,id(),method_code,str);
}
//********************************************************************************
GuiObject::GuiObject(const char* name) :m_auto_delete(1)
{
if (name==0)
{
WARN("Error: Attempt to create Object with no name");
}
else if (_swix(Toolbox_CreateObject,_INR(0,1)|_OUT(0),0,name,&m_id)!=NULL)
{
WARN("Error: Couldn't create %s",name);
m_id=NULL_GuiObjectId;
}
}
//********************************************************************************
GuiObject::GuiObject(GuiObjectId id) : m_id(id),m_auto_delete(0) {}
//********************************************************************************
GuiObject::~GuiObject()
{
if (m_auto_delete && id() != NULL_GuiObjectId)
{
_swix(Toolbox_DeleteObject,_INR(0,1),0,id());
}
}
//********************************************************************************
void GuiObject::show(int flags, int show_type,const void *type,
const GuiObject* parent,
GuiComponentId parent_component_id)
{
if (id() != NULL_GuiObjectId)
{
_swix(Toolbox_ShowObject,_INR(0,5),flags,id(),
show_type,type,
(parent ? parent->id() : NULL_GuiObjectId),
parent_component_id);
}
};
//********************************************************************************
void GuiObject::hide()
{
if (id() != NULL_GuiObjectId)
{
_swix(Toolbox_HideObject,_INR(0,1),0,id());
}
}
//********************************************************************************
bool GuiObject::isShowing() const
{
if (id() == NULL_GuiObjectId) return 0;
unsigned int state;
return (_swix(Toolbox_GetObjectState,_INR(0,1) | _OUT(0),0,id(),&state)==NULL)?state:0;
}
//********************************************************************************
//********************************************************************************
//********************************************************************************
GuiWindowObject::~GuiWindowObject() {}
//********************************************************************************
void GuiWindowObject::showAtPointer(int flags,
const GuiObject* parent,
GuiComponentId parent_component_id,
const GuiTopLeft* offset)
{
GuiPointerInfo pib;
GuiGetWindowStateBlock ws;
GuiWindow(underlyingWindowId()).getState(ws);
pib.x += (offset)?offset->x:-64;
pib.y += (offset)?offset->y:0;
ws.visibleArea.moveTo(pib.x,pib.y);
ws.behind=-1;
GuiObject::show(flags,ShowTypeFullSpec,&ws.visibleArea,parent,parent_component_id);
}
//********************************************************************************
void GuiWindowObject::showCentred(int flags,
int offset_x,int offset_y,
const GuiWindowObject* centre_in_this_window,
const GuiObject* parent,
GuiComponentId parent_component_id)
{
GuiGetWindowStateBlock bounds;
if (centre_in_this_window)
{
GuiWindow(centre_in_this_window->underlyingWindowId()).getState(bounds);
}
else
{
bounds.visibleArea.xmin=0;
bounds.visibleArea.ymin=0;
bounds.visibleArea.xmax=gfx::screenwidth();
bounds.visibleArea.ymax=gfx::screenheight();
}
GuiGetWindowStateBlock ws;
GuiWindow(underlyingWindowId()).getState(ws);
ws.visibleArea.centreInBox(bounds.visibleArea);
ws.visibleArea.moveBy(offset_x,offset_y);
ws.behind=-1;
GuiObject::show(flags,ShowTypeFullSpec,&ws.visibleArea,parent,parent_component_id);
}
//********************************************************************************